
package com.lottery.dao.hibernate;

import java.util.List;

import com.lottery.dao.hibernate.BaseDaoHibernate;
import com.lottery.model.Lottery638;
import com.lottery.dao.Lottery638Dao;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.HibernateCallback;

public class Lottery638DaoHibernate extends BaseDaoHibernate implements Lottery638Dao {

    /**
     * @see com.lottery.dao.Lottery638Dao#getLottery638s(com.lottery.model.Lottery638)
     */
    public List getLottery638s(final Lottery638 lottery638) {
        //return getHibernateTemplate().find("from Lottery638");

        /* Remove the line above and uncomment this code block if you want 
           to use Hibernate's Query by Example API.*/
        if (lottery638 == null) {
            return getHibernateTemplate().find("from Lottery638 order by no0 desc");
        } else {
            // filter on properties set in the lottery638
            HibernateCallback callback = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    Example ex = Example.create(lottery638).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    Criteria criteria = session.createCriteria(Lottery638.class);
                    criteria.addOrder(Order.desc("no0"));
                    return criteria.add(ex).list();
                    //return session.createCriteria(Lottery638.class).add(ex).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }
    }

    /**
     * @see com.lottery.dao.Lottery638Dao#getLottery638(Long id)
     */
    public Lottery638 getLottery638(final Long id) {
        Lottery638 lottery638 = (Lottery638) getHibernateTemplate().get(Lottery638.class, id);
        if (lottery638 == null) {
            log.warn("uh oh, lottery638 with id '" + id + "' not found...");
            throw new ObjectRetrievalFailureException(Lottery638.class, id);
        }

        return lottery638;
    }

    /**
     * @see com.lottery.dao.Lottery638Dao#saveLottery638(Lottery638 lottery638)
     */    
    public void saveLottery638(final Lottery638 lottery638) {
        getHibernateTemplate().saveOrUpdate(lottery638);
    }

    /**
     * @see com.lottery.dao.Lottery638Dao#removeLottery638(Long id)
     */
    public void removeLottery638(final Long id) {
        getHibernateTemplate().delete(getLottery638(id));
    }
}
